import { useRegisterListOptions } from '/@/views/common/commonSetting';
import { useI18n } from '/@/hooks/web/useI18n';

const { registerListOptions } = useRegisterListOptions();
const { t } = useI18n();
// 注册配置表单

export function useBaseOptionList() {
  const { t } = useI18n();
  const baseOptionList = [
    { label: t('table.system.system_set1'), value: '1' },
    { label: t('table.system.system_set2'), value: '2' },
    { label: t('table.system.system_set3'), value: '3' },
    { label: t('table.system.system_set4'), value: '4' },
    { label: t('table.system.system_set5'), value: '5' },
    // { label: '短信上行验证', value: '6' },
    { label: t('table.system.system_set7'), value: '7' },
    { label: t('table.system.system_set8'), value: '8' },
    { label: t('table.system.system_set9'), value: '9' },
  ];
  return { baseOptionList };
}

export function registerSchema() {
  const { baseOptionList } = useBaseOptionList();
  return [
    {
      field: 'basic-setting',
      component: 'Input',
      label: '',
      colProps: {
        span: 24,
      },
      slot: 'basicInfo',
    },
    {
      field: 'reg_web',
      component: 'CheckboxGroup',
      label: t('modalForm.system.system_registration_configuration') + ':',
      required: true,
      labelWidth: 120,
      colProps: { span: 24 },
      slot: 'regWeb',
    },
    {
      field: 'reg_app',
      component: 'CheckboxGroup',
      label: t('modalForm.system.system_app_configuration') + ':',
      required: true,
      labelWidth: 120,
      colProps: { span: 24 },
      componentProps: {
        options: registerListOptions,
      },
      slot: 'regApp',
    },
    {
      field: 'ipLimit',
      component: 'Input',
      label: t('table.system.system_ip_limit'),
      colProps: {
        span: 8,
        style: {
          marginLeft: '12px',
        },
      },
      componentProps: () => {
        return {
          allowClear: false,
          maxLength: 2,
          placeholder: t('table.system.system_ip_limit_tips'),
          onChange: (e) => {
            // 禁止输入空格
            let val = e?.target?.value ?? null;
            // 替换输入值，只保留数字0
            if (val) {
              val = val.replace(/[^\d]/g, '');

              e.target.value = val;
            }
          },
        };
      },
    },
    {
      field: 'vertification-setting',
      component: 'Input',
      label: '',
      colProps: {
        span: 24,
      },
      slot: 'vertificationTitle',
    },
    {
      field: 'webSetting',
      component: 'RadioGroup',
      label: `Web${t('table.promotion.promotion_step5_GTM_title')}：`,
      defaultValue: 1,

      colProps: {
        span: 24,
      },
      componentProps: {
        options: baseOptionList,
      },
    },
    {
      field: 'appSetting',
      component: 'RadioGroup',
      label: `APP${t('table.promotion.promotion_step5_GTM_title')}：`,
      defaultValue: 1,
      colProps: {
        span: 24,
      },
      componentProps: {
        options: baseOptionList,
      },
    },
  ];
}
